const createI18nInstance = (lang = "zh_CN") => {
  const t = (langKey, option) => {
    // TODO：待补充代码 目标 1
    let nowLang = null;
    switch (lang) {
      case "zh_CN":
        nowLang = zh_CN;
        break;
      case "ja_JP":
        nowLang = ja_JP;
        break;
      case "en_US":
        nowLang = en_US;
        break;
    }
    let line = null;
    if (nowLang[langKey]) {
      line = nowLang[langKey];
    } else {
      const reg = /^(\w+).(\w+)$/;
      let arr = reg.exec(langKey);
      line = nowLang[arr[1]][arr[2]];
    }
    if (option != undefined)
      for (const key in option) {
        let str = `$$${key}$$`;
        line = line.replace(str, option[key]);
      }
    return line;
    // TODO：END
  };

  return {
    t,
  };
};

window.createI18nInstance = createI18nInstance;

// 目标 1 测试用例 zh_CN 对应

let { t } = createI18nInstance("zh_CN");

console.log(t("lanqiaoPrepare")); // 蓝桥杯备赛专区
console.log(t("nav.work")); //  就业
console.log(t("menuList.route")); // 学习路径
console.log(t("menuList.business", { num: 100 })); // 100大行业

// 目标 1 测试用例 en_US 对应
let { t: t2 } = createI18nInstance("en_US");

console.log(t2("lanqiaoPrepare")); // LanQiao Cup prep area
console.log(t2("nav.work")); //  Jobs
console.log(t2("menuList.route")); // Learning path
console.log(t2("menuList.business", { num: 100 })); // 100 business(es)

// 目标 1 测试用例 ja_JP 对应

let { t: t3 } = createI18nInstance("ja_JP");

console.log(t3("lanqiaoPrepare")); // ブルーブリッジ杯特設コーナー
console.log(t3("nav.work")); //  就職
console.log(t3("menuList.route")); // 学習経路
console.log(t3("menuList.business", { num: 100 })); // 100つの業界
